import entity.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import service.UserService;
import service.impl.UserServiceImpl;

public class SpringIOCTest {
    @Test
    public void SpringIoC(){
        //通过ClassPathXmlApplicationContext实例化Spring上下文
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        //通过AppliactionContext的getBean()方法，根据id来获取Bean的实例
        HelloSpring helloSpring= (HelloSpring) context.getBean("helloSpring");

        helloSpring.print();

        System.out.println(helloSpring.getWho());

    }
    @Test
    public void SpringAOP(){
        //通过ClassPathXmlApplicationContext实例化Spring上下文
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService= (UserService) context.getBean("userService");
        User user=new User();
        user.setId(1);
        user.setUsername("test");
        user.setPassword("123456");
        user.setEmail("dfsdfd");
        userService.addNewUser(user);
    }

    @Test
    public void SpringAOParound(){
        //通过ClassPathXmlApplicationContext实例化Spring上下文
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService= (UserService) context.getBean("userService");
        User user=new User();
        user.setId(1);
        user.setUsername("test");
        user.setPassword("123456");
        user.setEmail("dfsdfd");
        Object o = userService.addNewUser(user);
        System.out.println(o.toString());
    }
    @Test
    public void SpringZJioc(){
        //通过ClassPathXmlApplicationContext实例化Spring上下文
        ApplicationContext context=new ClassPathXmlApplicationContext("AppliactionContext.xml");
        UserService userService= (UserService) context.getBean("userService");
        User user=new User();
        userService.addNewUser2(user);
    }
}
